<?php

class ItemAction extends Action {

    public function view(){
    	$view = new Model('Item');
    	$com = new Model('Comments');
    	$id = intval($_GET['id']);
    	$content = $view->where("item_id='$id'")->select();
    	$list = $com->where("item_id = '$id'")->select();
    	$cate = $content[0][cate_id];
    	$up = $view->field('item_id')->where("cate_id = '$cate' and item_id < '$id'")->order('item_id desc')->limit('1')->select();
    	$down = $view->field('item_id')->where("cate_id = '$cate' and item_id > '$id'")->order('item_id asc')->limit('1')->select();
    	$up = $up[0]['item_id'];

    	$down = $down[0]['item_id'];
    	$this->assign('id',$id);
		$this->assign('list',$list);
    	$this->assign('up',$up);
    	$this->assign('down',$down);
    	$this->assign('con',$content);
    	$content = $this->fetch();
    	echo $content;
    	$path = ROOT."/public/tmp/".$id.".html";
    	$this->create($path, $content, $id);



    }

    public function insert(){
    	$com = new Model('Comments');
    	$test = $com->create();
    	$test[item_id]= $_GET['id'];
    	print_r($test);
    	$com->data($test)->add();
    	$this->redirect('view',array('id'=>$_GET['id']),1,'页面跳转中~~~');
    }

    function create($path, $content, $id){

    	file_put_contents($path,$content);
    }
}
?>